package com.sino.cloud.api.controller;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sino.cloud.api.domain.Swagger;
import com.sino.cloud.api.repo.SwaggerDocRepo;

/**
 * Project: zhcore
 *
 * @Comments
 * @Author Zhong Han
 * @Created Date 2017/4/6
 */

@RestController
@RequestMapping(path = "/api")
public class DocumentUI {

	@Autowired
	private SwaggerDocRepo swaggerDocRepo;

	@RequestMapping(path = "/", method = RequestMethod.GET)
	public Set<Swagger> getSwaggers() {
		return swaggerDocRepo.findAll();
	}

	@RequestMapping(path = "/{basePath}", method = RequestMethod.GET)
	public Swagger getByBasePath(@PathVariable String basePath) {
		if (!basePath.startsWith("/")) {
			basePath = "/" + basePath;
		}
		Swagger swagger = swaggerDocRepo.findByBasePath(basePath);
		return swagger;
	}

}
